

var moldZdjhDialog = {
	oThis: null,
	dialog: null,

	detail: null,

	init: function () {
		this.initState();
		this.initEvent();
	},

	initState: function () {
		this.oThis = $('#zdjhDialog');
		this.oFooter = this.oThis.find('._footer');
		this.dialog = new TheDialog('#zdjhDialog');
	},

	initEvent: function () {
		var _this = this;

		this.oThis.find('.submit-btn').on('click', function () {
			_this.submit();
		})
	},

	show: function (detail) {
		this.detail = detail;
		this.dialog.show();

		this.setDetailHtml();
	},

	submit: function () {
		var _this = this;
		var param = {
			id: this.detail.id
		}
		var jmjh = this.oThis.find('.jmjh-ipt').val();
		if (!jmjh) {
			Qmsg.error('请选择建模计划完成时间');
			return;
		} else {
			param.modePlanTime = jmjh;
		}
		var zmjh = this.oThis.find('.zmjh-ipt').val();
		if (!zmjh) {
			Qmsg.error('请选择制模计划完成时间');
			return;
		} else {
			param.makePlanTime = zmjh;
		}
		$.ajax({
			type: 'get',
			url: pb.api + '/task/makePlan',
			data: param,
			success: function (res) {
				if (res.result == "true") {
					_this.dialog.close();
					Qmsg.success('制定计划成功');
					oPage.getData();
				} else {
					Qmsg.error(res.message);
				}
			}
		})
	},

	setDetailHtml: function () {
		var html = '';

		this.oThis.find('.sqdh-text').html(this.detail ? this.detail.applyNo : '-');
		this.oThis.find('.sqsj-text').html(this.detail ? this.detail.applyTime : '-');
		this.oThis.find('.sqks-text').html(this.detail ? this.detail.deptName : '-');
		this.oThis.find('.sqys-text').html(this.detail ? this.detail.doctorName : '-');
		this.oThis.find('.hzxm-text').html(this.detail ? this.detail.patientName : '-');
		this.oThis.find('.xb-text').html(this.detail ? this.detail.sex : '-');
		this.oThis.find('.nl-text').html(this.detail ? this.detail.age : '-');
		this.oThis.find('.dzbw-text').html(this.detail ? this.detail.partName : '-');
		this.oThis.find('.jcbw-text').html(this.detail ? this.detail.checkPointMethod : '-');
		var jm = '';
		if (this.detail && this.detail.makePlanState == 1 && this.detail.modePlanTime) {
			jm = this.detail.modePlanTime.slice(0, 10);
		}
		this.oThis.find('.jmjh-ipt').val(jm);
		var zm = '';
		if (this.detail && this.detail.makePlanState == 1 && this.detail.makePlanTime) {
			zm = this.detail.makePlanTime.slice(0, 10);
		}
		this.oThis.find('.zmjh-ipt').val(zm);

		if (this.detail.downloadState != 1 || this.detail.makePlanState == 1) {
			this.oFooter.hide();
		} else {
			this.oFooter.show();
		}
	}
}

$(function () {
	moldZdjhDialog.init();
})

